module.exports = options =>{
 return   async (req, res, next) => {
     const jwt = require('jsonwebtoken')
     // 根据用户名找用户
     const User = require('../models/AdminUser')
     const assert = require('http-assert')
        const token = String(req.headers.authorization || '').split(' ').pop()
        /**
         * decode 解密不安全 用校验
         */
        assert(token, 401, "请先登录")
        const { id } = jwt.verify(token, req.app.get('secret'))
        assert(id, 401, "请先登录")
        req.user = await User.findById(id)
        console.log(req.user)
        assert(req.user, 401, '请先登录')
        await next()
    }
}